package com.bookcity.service;

import com.bookcity.dao.BookMapper;
import com.bookcity.pojo.BriefBook;
import com.bookcity.pojo.Comment;
import com.bookcity.pojo.DetailBook;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * BookServiceImpl
 *
 * @Author : lostprobe
 * @Date : 2022/6/30 18:25
 * @Brief : BookServiceImpl
 */
@Service
public class BookServiceImpl implements BookService{
    @Autowired
    private BookMapper bookMapper;

    @Override
    public DetailBook getBookById(long bid) {
        return bookMapper.getBookById(bid);
    }

    @Override
    public List<Comment> getComment(long bid) {
        return bookMapper.getComment(bid);
    }

    @Override
    public List<BriefBook> listBook(int pn, int rn, int zone, int type, int other) {
        return bookMapper.listBook(pn, rn, zone, type, other);
    }

    @Override
    public List<BriefBook> searchBooksByName(String bookname) {
        return bookMapper.searchBooksByName(bookname);
    }

    @Override
    public void updateBookStockById(long bid, int num) {
        DetailBook book = bookMapper.getBookById(bid);
        book.setStock(book.getStock() - num);
        bookMapper.updateDetailBookById(book);
    }
    @Override
    public int addOnBook(DetailBook detailBook) {
        return bookMapper.addOnBook(detailBook);
    }

    @Override
    public int deleteByBid(@Param("bid") long bid) {
        return bookMapper.deleteByBid(bid);
    }
}
